<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js">var roundRectHelper = require(&quot;../../utils/round_rect&quot;);

var dataUtil = require(&quot;../../utils/data_structure_util&quot;);

var _sub_pixel_optimize = require(&quot;../../utils/sub_pixel_optimize&quot;);

var subPixelOptimizeRect = _sub_pixel_optimize.subPixelOptimizeRect;

var Shape = require(&quot;./Shape&quot;);

function _typeof(obj) { &quot;@babel/helpers - typeof&quot;; if (typeof Symbol === &quot;function&quot; &amp;&amp; typeof Symbol.iterator === &quot;symbol&quot;) { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj &amp;&amp; typeof Symbol === &quot;function&quot; &amp;&amp; obj.constructor === Symbol &amp;&amp; obj !== Symbol.prototype ? &quot;symbol&quot; : typeof obj; }; } return _typeof(obj); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(&quot;Cannot call a class as a function&quot;); } }

function _defineProperties(target, props) { for (var i = 0; i &lt; props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (&quot;value&quot; in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call &amp;&amp; (_typeof(call) === &quot;object&quot; || typeof call === &quot;function&quot;)) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(&quot;this hasn&#39;t been initialised - super() hasn&#39;t been called&quot;); } return self; }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _inherits(subClass, superClass) { if (typeof superClass !== &quot;function&quot; &amp;&amp; superClass !== null) { throw new TypeError(&quot;Super expression must either be null or a function&quot;); } subClass.prototype = Object.create(superClass &amp;&amp; superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

<span id='qrenderer-graphic-shape-Rect'>/**
</span> * @class qrenderer.graphic.shape.Rect 
 * 矩形
 * @docauthor 大漠穷秋 &lt;damoqiongqiu@126.com&gt;
 */
// Avoid create repeatly.
var subPixelOptimizeOutputShape = {};

var Rect =
/*#__PURE__*/
function (_Shape) {
  _inherits(Rect, _Shape);

<span id='qrenderer-graphic-shape-Rect-method-constructor'>  /**
</span>   * @method constructor Rect
   * @param {Object} options 
   */
  function Rect(options) {
    var _this;

    _classCallCheck(this, Rect);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(Rect).call(this, dataUtil.merge({
      shape: {
        // 左上、右上、右下、左下角的半径依次为r1、r2、r3、r4
        // r缩写为1         相当于 [1, 1, 1, 1]
        // r缩写为[1]       相当于 [1, 1, 1, 1]
        // r缩写为[1, 2]    相当于 [1, 2, 1, 2]
        // r缩写为[1, 2, 3] 相当于 [1, 2, 3, 2]
        r: 0,
        x: 0,
        y: 0,
        width: 0,
        height: 0
      }
    }, options, true)));
<span id='qrenderer-graphic-shape-Rect-property-type'>    /**
</span>     * @property {String} type
     */

    _this.type = &#39;rect&#39;;
    return _this;
  }
<span id='qrenderer-graphic-shape-Rect-method-buildPath'>  /**
</span>   * @method buildPath
   * 绘制元素路径
   * @param {Object} ctx 
   * @param {String} shape 
   */


  _createClass(Rect, [{
    key: &quot;buildPath&quot;,
    value: function buildPath(ctx, shape) {
      var x;
      var y;
      var width;
      var height;

      if (this.subPixelOptimize) {
        subPixelOptimizeRect(subPixelOptimizeOutputShape, shape, this.style);
        x = subPixelOptimizeOutputShape.x;
        y = subPixelOptimizeOutputShape.y;
        width = subPixelOptimizeOutputShape.width;
        height = subPixelOptimizeOutputShape.height;
        subPixelOptimizeOutputShape.r = shape.r;
        shape = subPixelOptimizeOutputShape;
      } else {
        x = shape.x;
        y = shape.y;
        width = shape.width;
        height = shape.height;
      }

      if (!shape.r) {
        ctx.rect(x, y, width, height);
      } else {
        roundRectHelper.buildPath(ctx, shape);
      }

      ctx.closePath();
      return;
    }
  }]);

  return Rect;
}(Shape);

module.exports = Rect;</pre>
</body>
</html>
